package com.wjx.user_provider.dao;

import com.wjx.user_provider.model.Appointment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AppointmentDao {
    //添加预约
    @Insert("insert into appointment (user_id,service_id,appointment_time," +
            "appointment_location,phone,status,created_time,last_updated_time) " +
            "values (#{userId},#{serviceId},#{appointmentTime}," +
            "#{appointmentLocation},#{phone},#{status},#{createdTime}," +
            "#{lastUpdatedTime})")
    public int addAppointment(Appointment appointment);

    //根据用户id查询预约
    @Select("select * from appointment where user_id = #{userId} order by id desc")
    public List<Appointment> queryAppointmentByUserId(int userId);

    //查询所有预约
    @Select("select * from appointment")
    public List<Appointment> queryAllAppointment();

    //根据id查询预约
    @Select("select * from appointment where id = #{id}")
    public Appointment queryAppointmentById(int id);

    //根据id更新预约
    @Update("update appointment set user_id = #{userId},service_id = #{serviceId}," +
            "appointment_time = #{appointmentTime},appointment_location = #{appointmentLocation}," +
            "phone = #{phone},status = #{status},last_updated_time = #{lastUpdatedTime} " +
            "where id = #{id}")
    public int updateAppointmentById(Appointment appointment);

    //根据id删除预约
    @Delete("delete from appointment where id = #{id}")
    public int deleteAppointmentById(int id);
    //根据服务id查询预约
    @Select("select * from appointment where service_id = #{serviceId} order by id desc")
    public List<Appointment> queryAppointmentByServiceId(int serviceId);
    //根据关键词模糊查询
    public List<Appointment> queryLikeAppointment(@Param("keyword") String keyword);
    //根据服务id删除预约
    @Delete("delete from appointment where  service_id = #{serviceId}")
    public int deleteAppointmentByServiceId(int serviceId);
    //根据用户id删除预约
    @Delete("delete from appointment where  user_id = #{userId}")
    public int deleteAppointmentByUserId(int userId);
}